<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>首页</title>
<script type="text/javascript">
       var path = window.document.location.href;
        var pathName = window.document.location.pathname;
        var hostPath = path.substring(0, path.indexOf(pathName));
        var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);

	    document.write('<link rel="icon" href="' + projectName + '/favicon.ico">');

        document.write('<link rel="stylesheet" type="text/css" href="' + projectName + '/css/bootstrap/bootstrap.min.css">');
        document.write('<link rel="stylesheet" type="text/css" href="' + projectName + '/css/basic/login.css">');
        
        document.write('<scr' + 'ipt src="' + projectName + '/js/json/json2.js"></scr' + 'ipt>');
        document.write('<scr' + 'ipt src="' + projectName + '/js/jquery/jquery-3.4.1.min.js"></scr' + 'ipt>');
		document.write('<scr' + 'ipt src="' + projectName + '/js/jquery/jquery.validate.min.js"></scr' + 'ipt>');
		document.write('<scr' + 'ipt src="' + projectName + '/js/jquery/messages_zh.min.js"></scr' + 'ipt>');
        document.write('<scr' + 'ipt src="' + projectName + '/js/bootstrap/bootstrap.min.js"></scr' + 'ipt>');
        document.write('<scr' + 'ipt src="' + projectName + '/js/bootstrap/bootstrap.bundle.min.js"></scr' + 'ipt>');
    </script>
    <!-- Modernizr JS -->
	<script type="text/javascript">
		document.write('<scr' + 'ipt src="' + projectName + '/js/js/modernizr-2.6.2.min.js"></scr' + 'ipt>');
	</script>
<!-- FOR IE9 below -->
<!--[if lt IE 9]>
	<script type="text/javascript">
		document.write('<scr' + 'ipt src="' + projectName + '/js/js/respond.min.js"></scr' + 'ipt>');
	</script>
	<![endif]-->

</head>
<body class="style-3">
	<div class="header col-sm-6">
		<nav class="navbar navbar-expand-sm">
			<ul class="navbar-nav">
				<li class="nav-item">
					<a class="navbar-brand" title="南京银行" target="_self" href="#"> 
						<img alt="logo" id="logo_img" class="img-fluid" />
					</a>
				</li>
				<li class="nav-item system_name font-weight-bold"></li>
			</ul>
		</nav>
	</div>
	<div class="row">
		<div class="login_bg">
			<div class="col-sm-5 login_area ml-auto">
				<form action="#" id="submitForm" class="fh5co-form">
					<h2>登录</h2>
					<div class="input-group">
						<div class="input-group-prepend">
							<img alt="username" id="usr_img" class="image-fluid" />
						</div>
						<input type="text" class="form-control" id="username"
						    name="username"
							placeholder="请输入登录用户名" autocomplete="off"
							autofocus="autofocus">
					</div>
					<div class="input-group">
						<div class="input-group-prepend">
							<img alt="password" id="pwd_img" class="image-fluid" />
						</div>
						<input type="password" class="form-control" 
						id="password" name="password"
						placeholder="请输入登录密码" autocomplete="off">
					</div>
					<div id="login_form_checkcode" class="input-group">
						<div class="input-group-prepend">
							<img alt="verify" id="verify_img" class="image-fluid" />
						</div>
						<input type="text" id="checkcode" name="checkcode"
							class="form-control" placeholder="请输入验证码"
							autocomplete="off"/> &nbsp;
						<div class="input-group-append">
							<img border=0 src="#" alt="点击重新加载" id="codeimg" class="img-fluid" />
						</div>

					</div>
					<div class="input-group">
						<input type="submit" id="submit_btn" name="submit_btn" 
						value="登录"  class="btn btn-primary"> 
						<input type="button" value="重置" id="reset_btn" name="reset_btn"
						class="btn btn-primary">
						&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="button" value="注册" id="register_btn" name="register_btn"
						class="btn btn-primary">
					</div>
				</form>
			</div>
		</div>
	</div>
	
	<div class="navbar navbar-expand-sm bg-white navbar-white">
		<div class="navbar_div">
			<div>江苏省南京市</div>
			<div>Licensed under the Apache License, Version 2.0</div>
			<div>苏ICP备18036471号</div>
		</div>
	</div>
	
	<!-- 信息提示框 -->
	<div class="alert alert-warning alert-dismissible">
	  <button type="button" class="close" data-dismiss="alert">&times;</button>
	  <span class="tips"></span>
	</div>
</body>

<script type="text/javascript">
		$(document).ready(function(){
	        $("#logo_img").attr("src", projectName + "/images/login/njbk.jpg"); 
	        $("#usr_img").attr("src", projectName + "/images/login/name.png");
	        $("#pwd_img").attr("src", projectName + "/images/login/password.png");
	        $("#verify_img").attr("src", projectName + "/images/login/verify.png");
	        $("#codeimg").attr('src', projectName + "/images/login/codeload.gif");
	        if($("#checkcode").is(":visible")){
            	$("#checkcode").attr("required", "true");
            }
	        
	        $(".alert").hide();
	       
	        
	        //自动加载验证码
	        var checkCode = false;
	        $.ajax({
	            type: "POST",
	            url: projectName + "/index/param",
				crossDomain:true,
				xhrFields:{
					withCredentials:true
				},
	            dataType: "json",
	            success: function (data) {
	                var indexParam = data.entity;
	                checkCode = indexParam.checkCode;
	                if (checkCode) {
	                    $("#codeimg").click();
	                    alert(checkCode);
	                    $("#login_form_checkcode").show();
	                } else {
	                    $("#login_form_checkcode").hide();
	                }
	                $(".system_name").html(indexParam.sysName);
	                $(document).attr("title", indexParam.sysName);
	            }
	        });

	        //form表单校验
	        var validate = $("#submitForm").validate({
                debug: false, //调试模式取消submit的默认提交功能   
                //errorClass: "label.error", //默认为错误的样式类为：error   
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
                onkeyup: false,   
                submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form   
                   // alert("提交表单");   
                    $.ajax({
                    	url: projectName + "/login",     //后台处理程序
						crossDomain:true,
						xhrFields:{
							withCredentials:true
						},
    				    type: "post",               //数据发送方式
    				    dataType: "json",           //接受数据格式   
    				    data: $('#submitForm').serialize(),
    	                success: function (data) {
    	                    var success = data.success;
    	                    console.log(data);
    	                    if (success) {
    	                        $.get(projectName + "/html/home/index.html", function (res) {
    	                            document.write(res);
    	                        });
    	                    } else {
    	                    	errorMsg = data.message;
    	                    	$(".tips").text(errorMsg);
    	     	             	$('.alert').show();
    	     	             	//alert(errorMsg);
    	     	             	event.preventDefault();
    	     	             	return false;
    	                    }
    	                },
    	                error: function (data) {
    	                	errorMsg = data.responseText;
    	                	$(".tips").text(errorMsg);
    	 	             	$('.alert').show();
    	 	             	//alert('bbb');
    	 	             	event.preventDefault();
    	 	             	return false;
    	                }
                    });  
                },   
                
                rules:{
                    username:{
                        required:true
                    },
                    password:{
                        required:true,
                        rangelength:[1,8]
                    },  
                    checkcode:{
                    	required: true,
                    	rangelength:[1,4],
                    	number: true
                    }               
                },
                messages:{
                    username:{
                        required:"用户名不能为空"
                    },
                    password:{
                        required: "密码不能为空",
                        rangelength: "密码最小长度:{0}, 最大长度:{1}。"
                    },
                    checkcode:{
                        required: "验证码不能为空",
                        rangelength: "验证码最小长度:{0}, 最大长度:{1}。"

                    }                                    
                }
                          
            });    
    	        
		});  
		
		//点击验证码图片，刷新验证码
        $("#codeimg").click(function(){
        	 var srcurl = projectName + "/index/validcode?t=" + Math.random();
        	$(this).attr("src", srcurl);
        });
		
		$("#reset_btn").click(function(){
			$("#username").val('');
			$("#password").val('');
			if($("#checkcode").is(":visible")){
            	$("#checkcode").val('');
            }
		});
		
		$("#register_btn").click(function(){
			var registerUrl = projectName + "/register";
			$(location).attr('href', registerUrl);
		});
		
	</script>

</html>